<?php

namespace app\admin\model;

use think\model\Relation;

class MobileOrder extends Relation {

        protected $link = array(
            'tours' => array(
                'mapping_type' => BELONGS_TO,
                'class_name' => 'Tours',
                'foreign_key' => 'line_id',
                'mapping_fields' => 'title,code',
                'as_fields' => 'title,code',
                'parent_key' => 'id'
            ),
            'supplier' => array(
                'mapping_type' => BELONGS_TO,
                'class_name' => 'Supplier',
                'foreign_key' => 'supplier_id',
                'mapping_fields' => 'name as supplier_name',
                'as_fields' => 'supplier_name',
                'parent_key' => 'id'
            ),
        );

        protected function _after_select(&$resultSet, $options=array()) {
                parent::_after_select($resultSet, $options);
                foreach ($resultSet as $key => $value) {
                        $resultSet[$key]['tours_url'] = U("/xianlu/" . $value['line_id'],  '', 'html', 'www');
                }
        }

        protected function _after_find(&$result, $options=array()) {
                parent::_after_find($result, $options);
                $result['tours_url'] = U("/xianlu/" . $result['line_id'],  '', 'html', 'www');
        }
}
